from django import forms
from django.forms import widgets as ws

from apps.case.models import Case as Cases


class CaseForm(forms.Form):
    case_num = forms.CharField(max_length=20, required=True, label='用例编号', empty_value='111',
                               error_messages={
                                   'required': '用例编号不能为空',
                                   'invalid': '请重新输入用例编号'
                                   },
                               widget=forms.TextInput(attrs={'class': 'form-control', 'placeholder': '请输入测试编号'}),
                               )
    name = forms.CharField(max_length=20, required=True, label='用例标题', empty_value='111',
                           error_messages={
                               'required': '用例标题不能为空',
                               'invalid': '请重新输入用例标题'
                               },
                           widget=forms.TextInput(attrs={'class': 'form-control', 'placeholder': '请输入测试编号'}),
                           )
    type = forms.CharField(widget=forms.Select(choices=[],
                                               attrs={
                                                   'class': 'selectpicker  bla bli form-control',
                                                   'data-live-search': 'true',
                                                   'style': 'display: none'
                                               }), label='用例类型')
    level = forms.CharField(widget=forms.Select(choices=[],
                                                attrs={
                                                    'class': 'selectpicker  bla bli form-control',
                                                    'data-live-search': 'true',
                                                    'style': 'display: none'
                                                }), label='优先级')

    def __init__(self, *args, **kwargs):
        super(CaseForm, self).__init__(*args, **kwargs)
        self.fields['type'].widget.choices = Cases.case_type
        self.fields['level'].widget.choices = Cases.case_level


class CaseModelForm(forms.ModelForm):
    class Meta:
        model = Cases
        fields = ['case_num', 'name', 'level', 'detail']
        exclude = ['expect', 'status', 'type', 'suite']
        labels = {
            'case_num': '用例编号',
            'name': '用例标题',
            # 'type': '用例类型',
            # 'suite': '测试集',
            'level': '用例级别',
            'detail': '用例描述',
            }
        widgets = {
            'case_num': ws.TextInput(attrs={"class": "form-control"}),
            "name": ws.TextInput(attrs={"class": "form-control"}),
            # "type": ws.Select(attrs={
            #     "class": "selectpicker bla bli form-control", "data-live-search": 'true', 'style': 'display: none'
            #     }),
            'detail': ws.TextInput(attrs={"class": "form-control"}),
            "level": ws.Select(attrs={
                "class": "selectpicker bla bli form-control", "data-live-search": 'true', 'style': 'display: none'
                }),
            }
